{	Problem: http://codeforces.ru/problemset/problem/61/B
 	Verdict: Accepted
}
uses sysutils;
var i,j,n:longint; s1,s2,s3,t:string; a:array[1..6] of string;
begin
readln(s1);
readln(s2);
readln(s3);
i:=1;
while i<=length(s1) do
  if (s1[i]='-') or (s1[i]='_') or (s1[i]=';') then delete(s1,i,1) else inc(i);
i:=1;
while i<=length(s2) do
  if (s2[i]='-') or (s2[i]='_') or (s2[i]=';') then delete(s2,i,1) else inc(i);
i:=1;
while i<=length(s3) do
  if (s3[i]='-') or (s3[i]='_') or (s3[i]=';') then delete(s3,i,1)  else inc(i);
s1:=UpperCase(s1);
s2:=uppercase(s2);
s3:=uppercase(s3);
a[1]:=s1+s2+s3;
a[2]:=s1+s3+s2;
a[3]:=s2+s3+s1;
a[4]:=s2+s1+s3;
a[5]:=s3+s1+s2;
a[6]:=s3+s2+s1;
readln(n);
for i:=1 to n do begin
  readln(t);
  j:=1;
  while j<=length(t) do
    if (t[j]=';') or (t[j]='_') or (t[j]='-') then delete(t,j,1) else inc(j);
  t:=uppercase(t);
  if (t=a[1]) or (t=a[2]) or (t=a[3]) or (t=a[4]) or (t=a[5]) or (t=a[6]) then writeln('ACC') else writeln('WA');
end;
end.